
/// 前端分页
/// url: 请求地址
/// page: 当前页码
/// page_size: 每页显示条数
/// total: 总条数
/// search: 搜索条件
/// 返回分页链接
pub fn pagination_link(url: &str, page: i64, page_total: i64, total: i64, query: &str) -> String {
    // search param
    if page_total <= 1 {
        return "".to_string();
    }
    let mut res = String::from("");
    res.push_str(format!("<li class='page-item disabled'><span class='page-link'>{}/{} {} Records</span></li>", page, page_total, total).as_str());

    // first page
    let url_str = format!("{}?page=1{}", url, query);
    res.push_str(format!("<li class='page-item'><a class='page-link' href='{}'>First</a></li>", url_str).as_str());

    // prev page 
    if page - 1 > 0 {
        let url_str = format!("{}?page={}{}", url, page - 1, query);
        res.push_str(format!("<li class='page-item'><a class='page-link' href='{}'>Prev</a></li>", url_str).as_str());
    }

    // page number
    let mut page_start = 1;
    let mut page_end = 6;
    if page_total > 5 {
        if page < 3 {
            page_start = 1;
            page_end = 6;
        } else if page > page_total - 3 {
            page_start = page_total - 4;
            page_end = page_total + 1;
        }
    } else {
        page_start = 1;
        page_end = page_total + 1;
    }
    for i in page_start..page_end {
        let mut active_str = String::from("");
        if i == page {
            active_str = " active".to_string();
        }
        let url_str = format!("{}?page={}{}", url, i, query);
        res.push_str(format!("<li class='page-item {}'><a class='page-link' href='{}'>{}</a></li>", active_str, url_str, i).as_str());
    }


    // next page 
    if page + 1 <= page_total {
        let url_str = format!("{}?page={}{}", url, page + 1, query);
        res.push_str(format!("<li class='page-item'><a class='page-link' href='{}'>Next</a></li>", url_str).as_str());
    }

    // last page
    let url_str = format!("{}?page={}{}", url, page_total, query);
    res.push_str(format!("<li class='page-item'><a class='page-link' href='{}'>Last</a></li>", url_str).as_str());


    res
}

pub fn get_total_page(page_size: i64, total: i64) -> i64 {
    let mut total_pages = total / page_size;
    if total % page_size > 0 {
        total_pages += 1;
    }
    total_pages
}